package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;

import com.ruoyi.system.vo.EditAuthReq;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TUser;
import com.ruoyi.web.service.ITUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户Controller
 *
 * @author ruoyi
 * @date 2020-11-20
 */
@Controller
@RequestMapping("/system/tuser")
public class TUserController extends BaseController {
    private String prefix = "system/tuser";

    @Autowired
    private ITUserService tUserService;

    @RequiresPermissions("system:tuser:view")
    @GetMapping()
    public String tuser() {
        return prefix + "/tuser";
    }

    /**
     * 查询用户列表
     */
    @RequiresPermissions("system:tuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TUser tUser) {
        startPage();
        List<Map<String, String>> list = tUserService.selectTUserList(tUser);
        return getDataTable(list);
    }


    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("system:tuser:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TUser tUser) {
        return toAjax(tUserService.insertTUser(tUser));
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Map<String, String> tUser = tUserService.selectTUserById(id);
        mmap.put("tUser", tUser);
        return prefix + "/edit";
    }


    /**
     * 实名认证
     */
    @GetMapping("/editname/{id}")
    public String editname(@PathVariable("id") String id, ModelMap mmap) {
        Map<String, String> tUser = tUserService.selectTUserById(id);
        mmap.put("tUser", tUser);
        return prefix + "/editname";
    }


    /**
     * 房屋认证
     */
    @GetMapping("/edithouse/{id}")
    public String edithouse(@PathVariable("id") String id, ModelMap mmap) {
        Map<String, String> tUser = tUserService.selectTUserById(id);
        mmap.put("tUser", tUser);
        return prefix + "/edithouse";
    }


    /**
     * 车辆认证
     */
    @GetMapping("/editcar/{id}")
    public String editcar(@PathVariable("id") String id, ModelMap mmap) {
        Map<String, String> tUser = tUserService.selectTUserById(id);
        mmap.put("tUser", tUser);
        return prefix + "/editcar";
    }


    /**
     * 审核用户认证资料
     */
    @Log(title = "审核用户认证资料", businessType = BusinessType.UPDATE)
    @PostMapping("/editauth")
    @ResponseBody
    public AjaxResult editAuth(EditAuthReq editAuthReq) {
        return toAjax(tUserService.editAuth(editAuthReq));
    }


    /**
     * 修改保存用户
     */
    @RequiresPermissions("system:tuser:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TUser tUser) {
        return toAjax(tUserService.updateTUser(tUser));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("system:tuser:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(tUserService.deleteTUserByIds(ids));
    }
}
